package com.exc4.jbv;

import lejos.nxt.Button;
import lejos.nxt.ButtonListener;
import lejos.nxt.LCD;
import lejos.nxt.SensorPort;

public class FindGoal {
	public static void main (String[] aArg) throws Exception
	{
		final int power = 80;
		Button.ESCAPE.addButtonListener(new ButtonListener() {
			
			@Override
			public void buttonReleased(Button b) {
				Car.stop();
			    LCD.clear();
			    LCD.drawString("Program stopped", 0, 0);
			    LCD.refresh();
			    System.exit(0);				
			}
			
			@Override
			public void buttonPressed(Button b) {
				// TODO Auto-generated method stub
				
			}
		});
	  
     ThreeColorSensor sensor = new ThreeColorSensor(SensorPort.S2, "Green");
	 
     sensor.calibrate();
	 
     LCD.clear();
     LCD.drawString("Light: ", 0, 2); 
	 
     while (true)
     {
    	 
    	 
    	 

	     LCD.drawInt(sensor.light(),4,10,2);
	     LCD.refresh();
	     
	     if (sensor.isThirdColor())
	    	 Car.stop();
	     else if(sensor.white())
	    	 Car.forward(0, power);
	     else
	    	 Car.forward(power, 0);	        
	     
	     Thread.sleep(10);
     }
   }
}
